package com.example.day10_27_multimode.slice;

import com.example.day10_27_multimode.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Component.TouchEventListener;
import ohos.agp.utils.Color;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.multimodalinput.event.MmiPoint;
import ohos.multimodalinput.event.TouchEvent;

public class MainAbilitySlice extends AbilitySlice {

   private final HiLogLabel LOG_LABEL = new HiLogLabel(0,0,"MY_Dag");
    private Button button;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        button = (Button) findComponentById(ResourceTable.Id_btn);
        button.setTouchEventListener(new TouchEventListener() {
            @Override
            public boolean onTouchEvent(Component component, TouchEvent touchEvent) {

                int pointerCount = touchEvent.getPointerCount();
                int action = touchEvent.getAction();
                MmiPoint Position = touchEvent.getPointerPosition(pointerCount - 1);
                float x = Position.getX();
                float y = Position.getY();

                HiLog.info(LOG_LABEL,"X:"+ x);
                HiLog.info(LOG_LABEL,"Y:"+ y);
                HiLog.info(LOG_LABEL," action :" +action);

                if (action == 1){
                    button.setText("松开发送");
                    button.setTextColor(Color.GREEN);
                } else if (x < 0 || x > 360 || y < 0 || y > 140) {
                    button.setText("松开取消");
                    button.setTextColor(Color.RED);
                }

                if (action == 2) {
                    button.setText("按住说话");
                    button.setTextColor(Color.BLACK);
                }


                return true;
            }
        });
    }



    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
